/*
 * @Description: 
 * @Author: Chenx
 * @Date: 2023-03-02 17:11:38
 * @LastEditors: Chenx
 * @LastEditTime: 2023-03-24 14:56:33
 */
import { defineConfig,loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import eslintPlugin from 'vite-plugin-eslint'
import AutoImport from 'unplugin-auto-import/vite'
import Components from "unplugin-vue-components/vite"
import { ElementPlusResolver,VantResolver } from 'unplugin-vue-components/resolvers'
// https://vitejs.dev/config/
export default defineConfig(({ mode, command }) => {
  const env = loadEnv(mode, process.cwd());
  return {
    plugins: [
      vue(),
      eslintPlugin({
        include: ['src/**/*.ts', 'src/**/*.vue', 'src/*.ts', 'src/*.vue'],
      }),
      AutoImport({
        dirs: ['src/utils'],
        imports: ['vue', 'vue-router'],
        dts: 'src/auto-imports.d.ts'
      }),
      Components({
        resolvers: [
          ElementPlusResolver(),
          VantResolver()
        ],
        dirs: ['src/components', 'src/layout'],
        dts: 'src/components.d.ts',
      }),
    ],
    resolve: {
      // 配置路径别名
      alias: {
        '@': '/src',
      },
    },
    css: {
      preprocessorOptions: {
        //define global scss variable
        scss: {
          additionalData: `
          @import "@/assets/style/_mixins.scss";
        `
        }
      }
    },
    server: {
      host: '0.0.0.0',
      port: 3000,    //设置服务启动端口
      open: true,    //设置服务启动时是否自动打开浏览器
      cors: true,    //允许跨域

      //设置代理
      proxy: {
        // 字符串简写写法
        // '/api': 'http://localhost:8060',
        // // 选项写法
        // '/urlApi':{
        // 	target:'http://localhost:8060',
        // 	changeOrigin: true,       //是否跨域
        // 	ws: true,            //是否代理 websockets
        // 	secure: true,          //是否https接口
        // 	// rewrite:(path) => path.replace('/urlApi/','/')
        // 	rewrite: (path) => path.replace(/^\/urlApi/, '')
        // },
        // 正则表达式写法
        '^/urlApi/.*': {
          target: 'http://localhost:3000',
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/urlApi/, '')
        },
      }
    }
  }
})
// export default defineConfig({
//   plugins: [
//     vue(),
//     eslintPlugin({
//       include: ['src/**/*.ts', 'src/**/*.vue', 'src/*.ts', 'src/*.vue'],
//     }),
//     AutoImport({
//       dirs: ['src/utils'],
//       imports: ['vue', 'vue-router'],
//       dts: 'src/auto-imports.d.ts'
//     }),
//     Components({
//       resolvers: [
//         ElementPlusResolver(),
//       ],
//       dirs: ['src/components', 'src/layout'],
//       dts: 'src/components.d.ts',
//     }),
//   ],
//   resolve: {
//     // 配置路径别名
//     alias: {
//       '@': '/src',
//     },
//   },
//   css: {
//     preprocessorOptions: {
//       //define global scss variable
//       scss: {
//         additionalData: `
//           @import "@/assets/style/_mixins.scss";
//         `
//       }
//     }
//   },
//   server: {
//     host: '0.0.0.0',
//     port: 3000,    //设置服务启动端口
//     open:true,    //设置服务启动时是否自动打开浏览器
//     cors: true,    //允许跨域

//     //设置代理
//     proxy: {
//       // 字符串简写写法
//       // '/api': 'http://localhost:8060',
//       // // 选项写法
//       // '/urlApi':{
//       // 	target:'http://localhost:8060',
//       // 	changeOrigin: true,       //是否跨域
//       // 	ws: true,            //是否代理 websockets
//       // 	secure: true,          //是否https接口
//       // 	// rewrite:(path) => path.replace('/urlApi/','/')
//       // 	rewrite: (path) => path.replace(/^\/urlApi/, '')
//       // },
//       // 正则表达式写法
//       '^/urlApi/.*': {
//         target: 'http://localhost:3000',
//         changeOrigin: true,
//         rewrite: (path) => path.replace(/^\/urlApi/, '')
//       },
//     }
//   }

// })
